export const FONT_SIZE_LIST = [
  { fontSize: 0.43 },
  { fontSize: 0.48 },
  { fontSize: 0.53 },
  { fontSize: 0.58 },
  { fontSize: 0.63 },
  { fontSize: 0.68 },
  { fontSize: 0.73 }
]

export const FONT_FAMILY = [
  { font: 'Default', name: '默认' },
  { font: 'LaoShiHeiTi', name: '筑紫黑体' },
  { font: 'ZengBoWeiBei', name: '求新魏碑' },
  { font: 'FangZhengXiJin', name: '方正细金' },
  { font: 'ZhangErKuiHei', name: '魁黑硬楷' }
]

export function themeList (vue) {
  return [
    {
      alias: vue.$t('book.themeDefault'),
      name: 'Default',
      style: {
        body: {
          color: '#4c5059',
          background: '#ffffff'
        }
      }
    },
    {
      alias: vue.$t('book.themeGold'),
      name: 'Gold',
      style: {
        body: {
          color: '#5c5b56',
          background: '#c6c2b6'
        }
      }
    },
    {
      alias: vue.$t('book.themeEye'),
      name: 'Eye',
      style: {
        body: {
          color: '#404c42',
          background: '#a9c1a9'
        }
      }
    },
    {
      alias: vue.$t('book.themeNight'),
      name: 'Night',
      style: {
        body: {
          color: '#cecece',
          background: '#000'
        }
      }
    }
  ]
}

export function addCss (href) {
  const link = document.createElement('link')
  link.setAttribute('rel', 'styleSheet')
  link.setAttribute('type', 'text/css')
  link.setAttribute('href', href)
  document.getElementsByTagName('head')[0].appendChild(link)
}

export function removeLink (href) {
  const links = document.getElementsByTagName('link')
  for (let i = links.length - 1; i >= 0; i--) {
    if (links[i] && links[i].getAttribute('href') === href) {
      console.log(links[i])
      links[i].parentNode.removeChild(links[i])
    }
  }
}
export function removeAllLink () {
  removeLink(`${process.env.VUE_APP_RES_URL}/theme/theme_default.css`)
  removeLink(`${process.env.VUE_APP_RES_URL}/theme/theme_eye.css`)
  removeLink(`${process.env.VUE_APP_RES_URL}/theme/theme_gold.css`)
  removeLink(`${process.env.VUE_APP_RES_URL}/theme/theme_night.css`)
}
